package com.blackoreo.monitor.entry;

import com.blackoreo.monitor.cache.BlackOreoCache;
import com.blackoreo.monitor.func.EntryMaker;

import java.util.HashSet;
import java.util.Objects;

/**
 * PackageName: com.blackoreo.monitor.entry
 * Author: txw
 * Date: 2021/4/8
 * Description: a couple of entry
 */
public class BlackOreoEntryGroup {

    public String groupName;

    private HashSet<BlackOreoEntry> entries;

    private String description;

    public BlackOreoEntryGroup(String groupName) {
        this.groupName = groupName;
        this.entries = new HashSet<>();
        BlackOreoCache.registry(this);
    }

    public BlackOreoEntryGroup(String groupName, String description) {
        this.groupName = groupName;
        this.description = description;
        this.entries = new HashSet<>();
        BlackOreoCache.registry(this);
    }

    public void addEntry (EntryMaker maker) {
        if (maker == null) throw new IllegalArgumentException("The entry maker cannot be null!");
        this.entries.add(maker.make());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BlackOreoEntryGroup that = (BlackOreoEntryGroup) o;
        return groupName.equals(that.groupName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(groupName);
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public HashSet<BlackOreoEntry> getEntries() {
        return entries;
    }

    public void setEntries(HashSet<BlackOreoEntry> entries) {
        this.entries = entries;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}
